﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 三国杀
{
    public partial class QQFindPwd: Form
    {
        public QQFindPwd()
        {
            InitializeComponent();
        }

        //找回密码按钮
        private void Find_button_Click(object sender, EventArgs e)
        {
            Find();
        }

        public void CompareAndGet()
        {
            DB db = new DB();//数据库对象
            db.dbOpen();                                            //打开数据库连接
            string sql = "select QQ, Pwd from QQUsers where sex='"
                 + this.textBox_sex.Text + "' and time='" +
                   this.textBox_birth.Text + "' and youxiang='" +
                   this.textBox_email.Text + "' and Phone='" +
                   this.textBox_phone.Text + "'";   //查询数据库是否有该用户

            SqlCommand comm = new SqlCommand(sql, db.Conn);         //创建SqlCommand对象
            SqlDataReader reader = comm.ExecuteReader();              //读取查询结果

            if (reader.Read())
            {
                string name = reader["QQ"].ToString();              //获取账号
                string password = reader["Pwd"].ToString();          //获取密码
                MessageBox.Show("信息正确，您的账号是：" + name + "，密码是：" + password);
                this.Hide();
                QQLogin login = new QQLogin();
                login.Show();
            }
            else
            {
                MessageBox.Show("信息有误，找回失败");
            }

            reader.Close();
            db.dbClose();                                           //关闭数据库连接
        }

        public void Find()
        {
            if (this.textBox_sex.Text != "")
            {
                if (this.textBox_birth.Text != "")
                {
                    if (this.textBox_email.Text != "")
                    {
                        if (this.textBox_phone.Text != "")
                        {
                            CompareAndGet();
                        }
                        else
                        {
                            MessageBox.Show("密保电话号不能为空请重新输入");
                            this.textBox_phone.Focus();
                        }
                    }
                    else
                    {
                        MessageBox.Show("QQ邮箱不能为空请重新输入");
                        this.textBox_email.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("出生日月不能为空请重新输入");
                    this.textBox_birth.Focus();                               //设置焦点到密码输入框
                }
            }
            else
            {
                MessageBox.Show("性别不能为空请重新输入");
                this.textBox_sex.Focus();
            }
        }
    }
}
